home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libhtml-parser-perl / examples / htextsub < prev    next >
Encoding:
Text File  |  2008-12-16  |  788 b   |  29 lines

  1. #!/usr/bin/perl -w
  2.  
  3. # Shows how to mangle all plain  text in an HTML document, using an arbitrary
  4. # Perl expression. Plain text is all text not within a tag declaration, i.e.
  5. # not in <p ...>, but possibly between <p> and </p>
  6.  
  7. use strict;
  8. my $code = shift || usage();
  9. $code = 'sub edit_print { local $_ = shift; ' . $code . '; print }';
  10. #print $code;
  11. eval $code;
  12. die $@ if $@;
  13.  
  14. use HTML::Parser 3.05;
  15. my $p = HTML::Parser->new(unbroken_text => 1,
  16.               default_h => [ sub { print @_; }, "text" ],
  17.                       text_h    => [ \&edit_print,      "text" ],
  18.                      );
  19.  
  20. my $file = shift || usage();
  21. $p->parse_file($file) || die "Can't open file $file: $!\n";
  22.  
  23. sub usage
  24. {
  25.     my $progname = $0;
  26.     $progname =~ s,^.*/,,;
  27.     die "Usage: $progname <perlexpr> <filename>\n";
  28. }
  29.